package com.ktv.ks.service.impl;

import com.ktv.ks.common.vo.R;
import com.ktv.ks.dao.AdminDao;
import com.ktv.ks.entity.Admin;
import com.ktv.ks.service.intf.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service  // IOC 创建对象
public class AdminServiceImpl implements AdminService {
    @Autowired  //为属性赋值，从IOC容器中
    private AdminDao dao;
    @Override
    public R login(String name, String password, HttpSession session) {
        //对参数进行校验
        if(name!=null && password!=null && name.length()>0 && password.length()>0){
            //查询数据库，用传递的用户名
            Admin admin=dao.selectByName(name);
            if(admin!=null){//用户名存在
                if(admin.getFlag()==1){
                    //验证用户是否有效
                    if(admin.getPassword().equals(password)){
                        //登录成功,存储当前用户到Session
                        session.setAttribute("curruser",admin);
                        return R.ok();
                    }else {
                        return R.fail("亲，密码有误");
                    }
                }else {
                    return R.fail("亲，账号被封，请联系客服");
                }
            }else{
                return R.fail("亲，账号不存在！");
            }
        }else {
            return R.fail("亲，请传递参数！");
        }
    }
}




